
var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
var imgUrl = globalData.imgUrl;
Page({

  data: {
    imgUrl: imgUrl,
    money: "",
    realMoney:"0.00",
    info:[],
  },
  //获取当前用户信息
  loadData: function () {
    var that = this;
    let openId = wx.getStorageSync("openidKey");
    wx.request({
      header: { "openId": openId, "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/takeCash/getPoundage",
      success: function (res) {
        res = res.data;
        console.log("手续费:" + JSON.stringify(res));
        if (res.result == 0) {
          var data = res.data;
          if (data!=null && data != ""){
            if (!commonUtil.isEmpty(data.withdraw_sum)){
              data.withdraw_sum = data.withdraw_sum.toFixed(2);
            }
            if (!commonUtil.isEmpty(data.withdraw_poundage)) {
              data.withdraw_poundage = data.withdraw_poundage+"%";
            }
          }
          that.setData({ info: data })
        }
      }
    })
  },
  putForward: function () {
    var params = new Object();
    let money = this.data.money;
    params.money = money;
    if (commonUtil.isEmpty(money)) {
      commonUtil.showModal("金额不能为空");
      return;
    }
    console.log(JSON.stringify(params));
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    wx.request({
      header: { "openId": openId, "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/takeCash/take",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        res = res.data;
        console.log("提现返回：" + JSON.stringify(res));
        if (res.result == 0) {
          wx.navigateTo({
            url: '../putforwardResult/putforwardResult',
          })
        } else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },
  money: function (e) {
    let val = e.detail.value;
    this.setData({ money: val,})
  },

  onLoad: function (options) {
    this.loadData();
  },
})